import re  
  
def write_args_to_file(filename, line):  
    args = line.split()  
    with open(filename, 'a') as file:  
        file.write(line + '\n') 
  
file_handles = {}  
index = 1 
with open('commands.log', 'r') as commands_file:  
    for line in commands_file:  
        line = line.strip()  
        first_arg = re.match(r'^\S+', line).group()  
        if first_arg not in file_handles:  
            filename = 'Proj_' + str(index) + '.txt'
            index = index + 1
            file_handles[first_arg] = open(filename, 'w')
        write_args_to_file(file_handles[first_arg].name, line)  
  
for handle in file_handles.values():  
    handle.close()
